var express = require('express');
var swig = require('swig');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var fs = require('fs');
var app = express();

app.use('/public',express.static(__dirname+'/public'));
app.use('/files',express.static(__dirname+'/files'));

app.use(cookieParser('qwertyuiop'));

app.engine('html',swig.renderFile);
app.set('views','./views/');
app.set('view engine','html');
swig.setDefaults({cache:false});

app.use(bodyParser.urlencoded({extended:true}));

app.use(function(req,res,next){
	if(req.cookies['login']){
		res.locals.login = req.cookies.login.username;
	}
	next();
})
app.use('/',require('./routers/main'));
app.use('/api',require('./routers/api'));

app.listen(3000,function(){
	console.log('running in 127.0.0.1:3000 ...');
})